//
//  DnpAlert.m
//  dnp_plugin
//
//

#import "DnpAlert.h"

@implementation DnpAlert

+ (void)show:(NSString *)text {
    
    NSString *title = @"Access Denied";
    NSString *close = @"Cancel";
    NSString *set = @"Settings";
    
    UIAlertController *actions = [UIAlertController alertControllerWithTitle:@"Access Denied"
                                                                       message:text
                                                                preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *closeAction = [UIAlertAction actionWithTitle:close
                                                           style:UIAlertActionStyleCancel
                                                         handler:nil];
    
    UIAlertAction *setAction = [UIAlertAction actionWithTitle:set
                                                             style:UIAlertActionStyleDefault
                                                           handler:^(UIAlertAction * _Nonnull action) {
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
        }
    }];

    

    [actions addAction:closeAction];
    [actions addAction:setAction];

    UIViewController *rootViewController = [UIApplication sharedApplication].windows.firstObject.rootViewController;
    if (rootViewController) {
        [rootViewController presentViewController:actions animated:YES completion:nil];
    }
}

@end
